package cn.ustb.controller;

import cn.ustb.entity.ExemptionApply;
import cn.ustb.entity.User;
import cn.ustb.service.ExemptionApplyService;
import cn.ustb.serviceImpl.ExemptionApplyServiceImpl;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author ljy
 */
@WebServlet("/exemptionApplyServlet")
public class ExemptionApplyServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ExemptionApplyService exemptionApplyService=new ExemptionApplyServiceImpl();
        request.setCharacterEncoding("utf-8");
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("user");
        String yearTerm = request.getParameter("yearTerm");
        String courseName = request.getParameter("courseName");
        String applyReason = request.getParameter("applyReason");

        ExemptionApply exemptionApply = new ExemptionApply(yearTerm, user.getUsername(), courseName, applyReason);
        exemptionApplyService.insert(exemptionApply);

        String message = "提交成功";
        session.setAttribute("message", message);
        response.sendRedirect(request.getContextPath() + "/exemptionapply.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }

}
